#############################################################
### Replication Code for Figures of Heterogeneous Effects ###
### Title: Relative Gains in the Shadow of a Trade War    ###
### Authors: Eddy S. F. Yeung and Kai Quek                ###
### Version: December 6, 2021                             ###
#############################################################

### Set-up ###
## Clean the R environment and set the working directory
# RStudio version: 1.3.959
rm(list = ls())
setwd("~/Downloads/trade_replication") # change to your own working directory

## Load the required packages
library(tidyverse) # version 1.3.1
library(ggpubr)    # version 0.4.0
library(plotrix)   # version 3.8-2
library(extrafont) # version 0.17
# windowsFonts("Times" = windowsFont("Times")) # may be required for Windows users

## Import the main dataset that contains all survey responses
df <- read.csv("trade.csv")

### Figure 2: Approval Rate of Removal of Import Limits by Nationalism ###
## Create empty data frames to store the results
df.nat1 <- vector("list", 2) # initialization
for(i in 1:2){
  df.nat1[[i]] <- as.data.frame(matrix(NA, nrow = 4, ncol = 5))
  df.nat1[[i]] <- df.nat1[[i]] %>% 
    rename(Subgroup = V1, Treatment = V2, 
           Approval = V3, Lower_bound = V4, Upper_bound = V5)
  df.nat1[[i]]$Subgroup <- c("Nationalist", "Non-Nationalist",
                             "Nationalist", "Non-Nationalist")
  df.nat1[[i]]$Treatment <- c("No Additional Vignette", "No Additional Vignette",
                              "Additional Vignette", "Additional Vignette")
}

## Store the approval rates (with CI) where the trade partner is China
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 3 & # no additional vignette
                                   (chau03 == 3 | chau03 == 4) # nationalist
                                 )))
df.nat1[[1]]$Lower_bound[1] <- temp[1]
df.nat1[[1]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 3 & # no additional vignette
                                   (chau03 == 1 | chau03 == 2) # non-nationalist
                   )))
df.nat1[[1]]$Lower_bound[2] <- temp[1]
df.nat1[[1]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 6 & # additional vignette
                                   (chau03 == 3 | chau03 == 4) # nationalist
                   )))
df.nat1[[1]]$Lower_bound[3] <- temp[1]
df.nat1[[1]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 6 & # additional vignette
                                   (chau03 == 1 | chau03 == 2) # non-nationalist
                   )))
df.nat1[[1]]$Lower_bound[4] <- temp[1]
df.nat1[[1]]$Upper_bound[4] <- temp[2]
df.nat1[[1]]$Approval <- (df.nat1[[1]]$Lower_bound + df.nat1[[1]]$Upper_bound) / 2

## Store the approval rates (with CI) where the trade partner is Country X
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 4 & # no additional vignette
                                   (chau03 == 3 | chau03 == 4) # nationalist
                   )))
df.nat1[[2]]$Lower_bound[1] <- temp[1]
df.nat1[[2]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 4 & # no additional vignette
                                   (chau03 == 1 | chau03 == 2) # non-nationalist
                   )))
df.nat1[[2]]$Lower_bound[2] <- temp[1]
df.nat1[[2]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 8 & # additional vignette
                                   (chau03 == 3 | chau03 == 4) # nationalist
                   )))
df.nat1[[2]]$Lower_bound[3] <- temp[1]
df.nat1[[2]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 8 & # additional vignette
                                   (chau03 == 1 | chau03 == 2) # non-nationalist
                   )))
df.nat1[[2]]$Lower_bound[4] <- temp[1]
df.nat1[[2]]$Upper_bound[4] <- temp[2]
df.nat1[[2]]$Approval <- (df.nat1[[2]]$Lower_bound + df.nat1[[2]]$Upper_bound) / 2

## Reorder factors
for(i in 1:2){
  df.nat1[[i]]$Subgroup <- 
    factor(df.nat1[[i]]$Subgroup, 
           levels = c("Nationalist", "Non-Nationalist"))
  df.nat1[[i]]$Treatment <- 
    factor(df.nat1[[i]]$Treatment, 
           levels = c("No Additional Vignette", "Additional Vignette"))
}

## Visualize the results for China
ggplot(data = df.nat1[[1]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Nationalist", "Non-Nationalist")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_nat1_China.pdf", width = 6, height = 6, dpi = 500)

## Visualize the results for Country X
ggplot(data = df.nat1[[2]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Nationalist", "Non-Nationalist")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_nat1_CntryX.pdf", width = 6, height = 6, dpi = 500)

### Figure 3: Approval Rate of Imposition of Import Limits by Nationalism ###
## Create empty data frames to store the results
df.nat2 <- vector("list", 2) # initialization
for(i in 1:2){
  df.nat2[[i]] <- as.data.frame(matrix(NA, nrow = 4, ncol = 5))
  df.nat2[[i]] <- df.nat2[[i]] %>% 
    rename(Subgroup = V1, Treatment = V2, 
           Approval = V3, Lower_bound = V4, Upper_bound = V5)
  df.nat2[[i]]$Subgroup <- c("Nationalist", "Non-Nationalist",
                             "Nationalist", "Non-Nationalist")
  df.nat2[[i]]$Treatment <- c("No Additional Vignette", "No Additional Vignette",
                              "Additional Vignette", "Additional Vignette")
}

## Store the approval rates (with CI) where the trade partner is China
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (chau03 == 3 | chau03 == 4) # nationalist
                   )))
df.nat2[[1]]$Lower_bound[1] <- temp[1]
df.nat2[[1]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (chau03 == 1 | chau03 == 2) # non-nationalist
                   )))
df.nat2[[1]]$Lower_bound[2] <- temp[1]
df.nat2[[1]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (chau03 == 3 | chau03 == 4) # nationalist
                   )))
df.nat2[[1]]$Lower_bound[3] <- temp[1]
df.nat2[[1]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (chau03 == 1 | chau03 == 2) # non-nationalist
                   )))
df.nat2[[1]]$Lower_bound[4] <- temp[1]
df.nat2[[1]]$Upper_bound[4] <- temp[2]
df.nat2[[1]]$Approval <- (df.nat2[[1]]$Lower_bound + df.nat2[[1]]$Upper_bound) / 2

## Store the approval rates (with CI) where the trade partner is Country X
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (chau03 == 3 | chau03 == 4) # nationalist
                   )))
df.nat2[[2]]$Lower_bound[1] <- temp[1]
df.nat2[[2]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (chau03 == 1 | chau03 == 2) # non-nationalist
                   )))
df.nat2[[2]]$Lower_bound[2] <- temp[1]
df.nat2[[2]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (chau03 == 3 | chau03 == 4) # nationalist
                   )))
df.nat2[[2]]$Lower_bound[3] <- temp[1]
df.nat2[[2]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (chau03 == 1 | chau03 == 2) # non-nationalist
                   )))
df.nat2[[2]]$Lower_bound[4] <- temp[1]
df.nat2[[2]]$Upper_bound[4] <- temp[2]
df.nat2[[2]]$Approval <- (df.nat2[[2]]$Lower_bound + df.nat2[[2]]$Upper_bound) / 2

## Reorder factors
for(i in 1:2){
  df.nat2[[i]]$Subgroup <- 
    factor(df.nat2[[i]]$Subgroup, 
           levels = c("Nationalist", "Non-Nationalist"))
  df.nat2[[i]]$Treatment <- 
    factor(df.nat2[[i]]$Treatment, 
           levels = c("No Additional Vignette", "Additional Vignette"))
}

## Visualize the results for China
ggplot(data = df.nat2[[1]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Nationalist", "Non-Nationalist")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_nat2_China.pdf", width = 6, height = 6, dpi = 500)

## Visualize the results for Country X
ggplot(data = df.nat2[[2]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Nationalist", "Non-Nationalist")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_nat2_CntryX.pdf", width = 6, height = 6, dpi = 500)

### Figure A3: Approval Rate of Removal of Import Limits by Nationalism (Full Sample) ###
## Create empty data frames to store the results
df.nat1 <- vector("list", 2) # initialization
for(i in 1:2){
  df.nat1[[i]] <- as.data.frame(matrix(NA, nrow = 4, ncol = 5))
  df.nat1[[i]] <- df.nat1[[i]] %>% 
    rename(Subgroup = V1, Treatment = V2, 
           Approval = V3, Lower_bound = V4, Upper_bound = V5)
  df.nat1[[i]]$Subgroup <- c("Nationalist", "Non-Nationalist",
                             "Nationalist", "Non-Nationalist")
  df.nat1[[i]]$Treatment <- c("No Additional Vignette", "No Additional Vignette",
                              "Additional Vignette", "Additional Vignette")
}

## Store the approval rates (with CI) where the trade partner is China
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 3 & # no additional vignette
                                   (chau03 == 3 | chau03 == 4 |  # nationalist
                                      knat03 == 3 | knat03 == 4) # nationalist
                   )))
df.nat1[[1]]$Lower_bound[1] <- temp[1]
df.nat1[[1]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 3 & # no additional vignette
                                   (chau03 == 1 | chau03 == 2 |  # non-nationalist
                                      knat03 == 1 | knat03 == 2) # non-nationalist
                   )))
df.nat1[[1]]$Lower_bound[2] <- temp[1]
df.nat1[[1]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 6 & # additional vignette
                                   (chau03 == 3 | chau03 == 4 |  # nationalist
                                      knat03 == 3 | knat03 == 4) # nationalist
                   )))
df.nat1[[1]]$Lower_bound[3] <- temp[1]
df.nat1[[1]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 6 & # additional vignette
                                   (chau03 == 1 | chau03 == 2 |  # non-nationalist
                                      knat03 == 1 | knat03 == 2) # non-nationalist
                   )))
df.nat1[[1]]$Lower_bound[4] <- temp[1]
df.nat1[[1]]$Upper_bound[4] <- temp[2]
df.nat1[[1]]$Approval <- (df.nat1[[1]]$Lower_bound + df.nat1[[1]]$Upper_bound) / 2

## Store the approval rates (with CI) where the trade partner is Country X
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 4 & # no additional vignette
                                   (chau03 == 3 | chau03 == 4 |  # nationalist
                                      knat03 == 3 | knat03 == 4) # nationalist
                   )))
df.nat1[[2]]$Lower_bound[1] <- temp[1]
df.nat1[[2]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 4 & # no additional vignette
                                   (chau03 == 1 | chau03 == 2 |  # non-nationalist
                                      knat03 == 1 | knat03 == 2) # non-nationalist
                   )))
df.nat1[[2]]$Lower_bound[2] <- temp[1]
df.nat1[[2]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 8 & # additional vignette
                                   (chau03 == 3 | chau03 == 4 |  # nationalist
                                      knat03 == 3 | knat03 == 4) # nationalist
                   )))
df.nat1[[2]]$Lower_bound[3] <- temp[1]
df.nat1[[2]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 8 & # additional vignette
                                   (chau03 == 1 | chau03 == 2 |  # non-nationalist
                                      knat03 == 1 | knat03 == 2) # non-nationalist
                   )))
df.nat1[[2]]$Lower_bound[4] <- temp[1]
df.nat1[[2]]$Upper_bound[4] <- temp[2]
df.nat1[[2]]$Approval <- (df.nat1[[2]]$Lower_bound + df.nat1[[2]]$Upper_bound) / 2

## Reorder factors
for(i in 1:2){
  df.nat1[[i]]$Subgroup <- 
    factor(df.nat1[[i]]$Subgroup, 
           levels = c("Nationalist", "Non-Nationalist"))
  df.nat1[[i]]$Treatment <- 
    factor(df.nat1[[i]]$Treatment, 
           levels = c("No Additional Vignette", "Additional Vignette"))
}

## Visualize the results for China
ggplot(data = df.nat1[[1]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Nationalist", "Non-Nationalist")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_nat1_China_alt.pdf", width = 6, height = 6, dpi = 500)

## Visualize the results for Country X
ggplot(data = df.nat1[[2]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Nationalist", "Non-Nationalist")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_nat1_CntryX_alt.pdf", width = 6, height = 6, dpi = 500)

### Figure A4: Approval Rate of Imposition of Import Limits by Nationalism (Full Sample) ###
## Create empty data frames to store the results
df.nat2 <- vector("list", 2) # initialization
for(i in 1:2){
  df.nat2[[i]] <- as.data.frame(matrix(NA, nrow = 4, ncol = 5))
  df.nat2[[i]] <- df.nat2[[i]] %>% 
    rename(Subgroup = V1, Treatment = V2, 
           Approval = V3, Lower_bound = V4, Upper_bound = V5)
  df.nat2[[i]]$Subgroup <- c("Nationalist", "Non-Nationalist",
                             "Nationalist", "Non-Nationalist")
  df.nat2[[i]]$Treatment <- c("No Additional Vignette", "No Additional Vignette",
                              "Additional Vignette", "Additional Vignette")
}

## Store the approval rates (with CI) where the trade partner is China
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (chau03 == 3 | chau03 == 4 |  # nationalist
                                      knat03 == 3 | knat03 == 4) # nationalist
                   )))
df.nat2[[1]]$Lower_bound[1] <- temp[1]
df.nat2[[1]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (chau03 == 1 | chau03 == 2 |  # non-nationalist
                                      knat03 == 1 | knat03 == 2) # non-nationalist
                   )))
df.nat2[[1]]$Lower_bound[2] <- temp[1]
df.nat2[[1]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (chau03 == 3 | chau03 == 4 |  # nationalist
                                      knat03 == 3 | knat03 == 4) # nationalist
                   )))
df.nat2[[1]]$Lower_bound[3] <- temp[1]
df.nat2[[1]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (chau03 == 1 | chau03 == 2 |  # non-nationalist
                                      knat03 == 1 | knat03 == 2) # non-nationalist
                   )))
df.nat2[[1]]$Lower_bound[4] <- temp[1]
df.nat2[[1]]$Upper_bound[4] <- temp[2]
df.nat2[[1]]$Approval <- (df.nat2[[1]]$Lower_bound + df.nat2[[1]]$Upper_bound) / 2

## Store the approval rates (with CI) where the trade partner is Country X
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (chau03 == 3 | chau03 == 4 |  # nationalist
                                      knat03 == 3 | knat03 == 4) # nationalist
                   )))
df.nat2[[2]]$Lower_bound[1] <- temp[1]
df.nat2[[2]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (chau03 == 1 | chau03 == 2 |  # non-nationalist
                                      knat03 == 1 | knat03 == 2) # non-nationalist
                   )))
df.nat2[[2]]$Lower_bound[2] <- temp[1]
df.nat2[[2]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (chau03 == 3 | chau03 == 4 |  # nationalist
                                      knat03 == 3 | knat03 == 4) # nationalist
                   )))
df.nat2[[2]]$Lower_bound[3] <- temp[1]
df.nat2[[2]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (chau03 == 1 | chau03 == 2 |  # non-nationalist
                                      knat03 == 1 | knat03 == 2) # non-nationalist
                   )))
df.nat2[[2]]$Lower_bound[4] <- temp[1]
df.nat2[[2]]$Upper_bound[4] <- temp[2]
df.nat2[[2]]$Approval <- (df.nat2[[2]]$Lower_bound + df.nat2[[2]]$Upper_bound) / 2

## Reorder factors
for(i in 1:2){
  df.nat2[[i]]$Subgroup <- 
    factor(df.nat2[[i]]$Subgroup, 
           levels = c("Nationalist", "Non-Nationalist"))
  df.nat2[[i]]$Treatment <- 
    factor(df.nat2[[i]]$Treatment, 
           levels = c("No Additional Vignette", "Additional Vignette"))
}

## Visualize the results for China
ggplot(data = df.nat2[[1]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Nationalist", "Non-Nationalist")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_nat2_China_alt.pdf", width = 6, height = 6, dpi = 500)

## Visualize the results for Country X
ggplot(data = df.nat2[[2]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Nationalist", "Non-Nationalist")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_nat2_CntryX_alt.pdf", width = 6, height = 6, dpi = 500)

### Figure A5: Approval Rate of Removal of Import Limits by Hawkishness ###
## Create empty data frames to store the results
df.hawk1 <- vector("list", 2) # initialization
for(i in 1:2){
  df.hawk1[[i]] <- as.data.frame(matrix(NA, nrow = 4, ncol = 5))
  df.hawk1[[i]] <- df.hawk1[[i]] %>% 
    rename(Subgroup = V1, Treatment = V2, 
           Approval = V3, Lower_bound = V4, Upper_bound = V5)
  df.hawk1[[i]]$Subgroup <- c("Hawk", "Dove", "Hawk", "Dove")
  df.hawk1[[i]]$Treatment <- c("No Additional Vignette", "No Additional Vignette",
                               "Additional Vignette", "Additional Vignette")
}

## Store the approval rates (with CI) where the trade partner is China
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 3 & # no additional vignette
                                   (hawk3 >= 5 & hawk3 <= 7) # hawk
                   )))
df.hawk1[[1]]$Lower_bound[1] <- temp[1]
df.hawk1[[1]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 3 & # no additional vignette
                                   (hawk3 >= 1 & hawk3 <= 4) # dove
                   )))
df.hawk1[[1]]$Lower_bound[2] <- temp[1]
df.hawk1[[1]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 6 & # additional vignette
                                   (hawk3 >= 5 & hawk3 <= 7) # hawk
                   )))
df.hawk1[[1]]$Lower_bound[3] <- temp[1]
df.hawk1[[1]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 6 & # additional vignette
                                   (hawk3 >= 1 & hawk3 <= 4) # dove
                   )))
df.hawk1[[1]]$Lower_bound[4] <- temp[1]
df.hawk1[[1]]$Upper_bound[4] <- temp[2]
df.hawk1[[1]]$Approval <- (df.hawk1[[1]]$Lower_bound + df.hawk1[[1]]$Upper_bound) / 2

## Store the approval rates (with CI) where the trade partner is Country X
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 4 & # no additional vignette
                                   (hawk3 >= 5 & hawk3 <= 7) # hawk
                   )))
df.hawk1[[2]]$Lower_bound[1] <- temp[1]
df.hawk1[[2]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 4 & # no additional vignette
                                   (hawk3 >= 1 & hawk3 <= 4) # dove
                   )))
df.hawk1[[2]]$Lower_bound[2] <- temp[1]
df.hawk1[[2]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 8 & # additional vignette
                                   (hawk3 >= 5 & hawk3 <= 7) # hawk
                   )))
df.hawk1[[2]]$Lower_bound[3] <- temp[1]
df.hawk1[[2]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 8 & # additional vignette
                                   (hawk3 >= 1 & hawk3 <= 4) # dove
                   )))
df.hawk1[[2]]$Lower_bound[4] <- temp[1]
df.hawk1[[2]]$Upper_bound[4] <- temp[2]
df.hawk1[[2]]$Approval <- (df.hawk1[[2]]$Lower_bound + df.hawk1[[2]]$Upper_bound) / 2

## Reorder factors
for(i in 1:2){
  df.hawk1[[i]]$Subgroup <- 
    factor(df.hawk1[[i]]$Subgroup, 
           levels = c("Hawk", "Dove"))
  df.hawk1[[i]]$Treatment <- 
    factor(df.hawk1[[i]]$Treatment, 
           levels = c("No Additional Vignette", "Additional Vignette"))
}

## Visualize the results for China
ggplot(data = df.hawk1[[1]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Hawk", "Dove")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_hawk1_China.pdf", width = 6, height = 6, dpi = 500)

## Visualize the results for Country X
ggplot(data = df.hawk1[[2]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Hawk", "Dove")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_hawk1_CntryX.pdf", width = 6, height = 6, dpi = 500)

### Figure A6: Approval Rate of Imposition of Import Limits by Hawkishness ###
## Create empty data frames to store the results
df.hawk2 <- vector("list", 2) # initialization
for(i in 1:2){
  df.hawk2[[i]] <- as.data.frame(matrix(NA, nrow = 4, ncol = 5))
  df.hawk2[[i]] <- df.hawk2[[i]] %>% 
    rename(Subgroup = V1, Treatment = V2, 
           Approval = V3, Lower_bound = V4, Upper_bound = V5)
  df.hawk2[[i]]$Subgroup <- c("Hawk", "Dove", "Hawk", "Dove")
  df.hawk2[[i]]$Treatment <- c("No Additional Vignette", "No Additional Vignette",
                               "Additional Vignette", "Additional Vignette")
}

## Store the approval rates (with CI) where the trade partner is China
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (hawk3 >= 5 & hawk3 <= 7) # hawk
                   )))
df.hawk2[[1]]$Lower_bound[1] <- temp[1]
df.hawk2[[1]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (hawk3 >= 1 & hawk3 <= 4) # dove
                   )))
df.hawk2[[1]]$Lower_bound[2] <- temp[1]
df.hawk2[[1]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (hawk3 >= 5 & hawk3 <= 7) # hawk
                   )))
df.hawk2[[1]]$Lower_bound[3] <- temp[1]
df.hawk2[[1]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (hawk3 >= 1 & hawk3 <= 4) # dove
                   )))
df.hawk2[[1]]$Lower_bound[4] <- temp[1]
df.hawk2[[1]]$Upper_bound[4] <- temp[2]
df.hawk2[[1]]$Approval <- (df.hawk2[[1]]$Lower_bound + df.hawk2[[1]]$Upper_bound) / 2

## Store the approval rates (with CI) where the trade partner is Country X
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (hawk3 >= 5 & hawk3 <= 7) # hawk
                   )))
df.hawk2[[2]]$Lower_bound[1] <- temp[1]
df.hawk2[[2]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (hawk3 >= 1 & hawk3 <= 4) # dove
                   )))
df.hawk2[[2]]$Lower_bound[2] <- temp[1]
df.hawk2[[2]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (hawk3 >= 5 & hawk3 <= 7) # hawk
                   )))
df.hawk2[[2]]$Lower_bound[3] <- temp[1]
df.hawk2[[2]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (hawk3 >= 1 & hawk3 <= 4) # dove
                   )))
df.hawk2[[2]]$Lower_bound[4] <- temp[1]
df.hawk2[[2]]$Upper_bound[4] <- temp[2]
df.hawk2[[2]]$Approval <- (df.hawk2[[2]]$Lower_bound + df.hawk2[[2]]$Upper_bound) / 2

## Reorder factors
for(i in 1:2){
  df.hawk2[[i]]$Subgroup <- 
    factor(df.hawk2[[i]]$Subgroup, 
           levels = c("Hawk", "Dove"))
  df.hawk2[[i]]$Treatment <- 
    factor(df.hawk2[[i]]$Treatment, 
           levels = c("No Additional Vignette", "Additional Vignette"))
}

## Visualize the results for China
ggplot(data = df.hawk2[[1]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Hawk", "Dove")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_hawk2_China.pdf", width = 6, height = 6, dpi = 500)

## Visualize the results for Country X
ggplot(data = df.hawk2[[2]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Hawk", "Dove")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_hawk2_CntryX.pdf", width = 6, height = 6, dpi = 500)

### Figure A7: Approval Rate of Imposition of Import Limits by Risk Preference ###
## Create empty data frames to store the results
df.risk <- vector("list", 2) # initialization
for(i in 1:2){
  df.risk[[i]] <- as.data.frame(matrix(NA, nrow = 6, ncol = 5))
  df.risk[[i]] <- df.risk[[i]] %>% 
    rename(Subgroup = V1, Treatment = V2, 
           Approval = V3, Lower_bound = V4, Upper_bound = V5)
  df.risk[[i]]$Subgroup <- c("Risk-Averse", "Risk-Neutral", "Risk-Seeking", 
                             "Risk-Averse", "Risk-Neutral", "Risk-Seeking")
  df.risk[[i]]$Treatment <- c("No Additional Vignette", "No Additional Vignette",
                              "No Additional Vignette", "Additional Vignette",
                              "Additional Vignette", "Additional Vignette")
}

## Store the approval rates (with CI) where the trade partner is China
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (risk1 >= 0 & risk1 <= 3) # risk-averse
                   )))
df.risk[[1]]$Lower_bound[1] <- temp[1]
df.risk[[1]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (risk1 >= 4 & risk1 <= 6) # risk-neutral
                   )))
df.risk[[1]]$Lower_bound[2] <- temp[1]
df.risk[[1]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   (risk1 >= 7 & risk1 <= 10) # risk-seeking
                   )))
df.risk[[1]]$Lower_bound[3] <- temp[1]
df.risk[[1]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (risk1 >= 0 & risk1 <= 3) # risk-averse
                   )))
df.risk[[1]]$Lower_bound[4] <- temp[1]
df.risk[[1]]$Upper_bound[4] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (risk1 >= 4 & risk1 <= 6) # risk-neutral
                   )))
df.risk[[1]]$Lower_bound[5] <- temp[1]
df.risk[[1]]$Upper_bound[5] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   (risk1 >= 7 & risk1 <= 10) # risk-seeking
                   )))
df.risk[[1]]$Lower_bound[6] <- temp[1]
df.risk[[1]]$Upper_bound[6] <- temp[2]
df.risk[[1]]$Approval <- (df.risk[[1]]$Lower_bound + df.risk[[1]]$Upper_bound) / 2

## Store the approval rates (with CI) where the trade partner is Country X
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (risk1 >= 0 & risk1 <= 3) # risk-averse
                   )))
df.risk[[2]]$Lower_bound[1] <- temp[1]
df.risk[[2]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (risk1 >= 4 & risk1 <= 6) # risk-neutral
                   )))
df.risk[[2]]$Lower_bound[2] <- temp[1]
df.risk[[2]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   (risk1 >= 7 & risk1 <= 10) # risk-seeking
                   )))
df.risk[[2]]$Lower_bound[3] <- temp[1]
df.risk[[2]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (risk1 >= 0 & risk1 <= 3) # risk-averse
                   )))
df.risk[[2]]$Lower_bound[4] <- temp[1]
df.risk[[2]]$Upper_bound[4] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (risk1 >= 4 & risk1 <= 6) # risk-neutral
                   )))
df.risk[[2]]$Lower_bound[5] <- temp[1]
df.risk[[2]]$Upper_bound[5] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   (risk1 >= 7 & risk1 <= 10) # risk-seeking
                   )))
df.risk[[2]]$Lower_bound[6] <- temp[1]
df.risk[[2]]$Upper_bound[6] <- temp[2]
df.risk[[2]]$Approval <- (df.risk[[2]]$Lower_bound + df.risk[[2]]$Upper_bound) / 2

## Reorder factors
for(i in 1:2){
  df.risk[[i]]$Subgroup <- 
    factor(df.risk[[i]]$Subgroup, 
           levels = c("Risk-Averse", "Risk-Neutral", "Risk-Seeking"))
  df.risk[[i]]$Treatment <- 
    factor(df.risk[[i]]$Treatment, 
           levels = c("No Additional Vignette", "Additional Vignette"))
}

## Visualize the results for China
ggplot(data = df.risk[[1]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Risk-Averse", "Risk-Neutral", "Risk-Seeking")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_risk_China.pdf", width = 6, height = 6, dpi = 500)

## Visualize the results for Country X
ggplot(data = df.risk[[2]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Risk-Averse", "Risk-Neutral", "Risk-Seeking")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.4,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_risk_CntryX.pdf", width = 6, height = 6, dpi = 500)

### Figure A8: Approval Rate of Imposition of Import Limits by Party Identification
## Create empty data frames to store the results
df.pid <- vector("list", 2) # initialization
for(i in 1:2){
  df.pid[[i]] <- as.data.frame(matrix(NA, nrow = 4, ncol = 5))
  df.pid[[i]] <- df.pid[[i]] %>% 
    rename(Subgroup = V1, Treatment = V2, 
           Approval = V3, Lower_bound = V4, Upper_bound = V5)
  df.pid[[i]]$Subgroup <- c("Republican", "Non-Republican",
                            "Republican", "Non-Republican")
  df.pid[[i]]$Treatment <- c("No Additional Vignette", "No Additional Vignette",
                             "Additional Vignette", "Additional Vignette")
}

## Store the approval rates (with CI) where the trade partner is China
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   republic == 1 # Republican
                   )))
df.pid[[1]]$Lower_bound[1] <- temp[1]
df.pid[[1]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 1 & # no additional vignette
                                   republic == 0 # non-Republican
                   )))
df.pid[[1]]$Lower_bound[2] <- temp[1]
df.pid[[1]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   republic == 1 # Republican
                   )))
df.pid[[1]]$Lower_bound[3] <- temp[1]
df.pid[[1]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 5 & # additional vignette
                                   republic == 0 # non-Republican
                   )))
df.pid[[1]]$Lower_bound[4] <- temp[1]
df.pid[[1]]$Upper_bound[4] <- temp[2]
df.pid[[1]]$Approval <- (df.pid[[1]]$Lower_bound + df.pid[[1]]$Upper_bound) / 2

## Store the approval rates (with CI) where the trade partner is Country X
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   republic == 1 # Republican
                   )))
df.pid[[2]]$Lower_bound[1] <- temp[1]
df.pid[[2]]$Upper_bound[1] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 2 & # no additional vignette
                                   republic == 0 # non-Republican
                   )))
df.pid[[2]]$Lower_bound[2] <- temp[1]
df.pid[[2]]$Upper_bound[2] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   republic == 1 # Republican
                   )))
df.pid[[2]]$Lower_bound[3] <- temp[1]
df.pid[[2]]$Upper_bound[3] <- temp[2]
temp <- confint(lm(supp1 ~ 1, 
                   data = subset(df, exp_group == 7 & # additional vignette
                                   republic == 0 # non-Republican
                   )))
df.pid[[2]]$Lower_bound[4] <- temp[1]
df.pid[[2]]$Upper_bound[4] <- temp[2]
df.pid[[2]]$Approval <- (df.pid[[2]]$Lower_bound + df.pid[[2]]$Upper_bound) / 2

## Reorder factors
for(i in 1:2){
  df.pid[[i]]$Subgroup <- 
    factor(df.pid[[i]]$Subgroup, 
           levels = c("Republican", "Non-Republican"))
  df.pid[[i]]$Treatment <- 
    factor(df.pid[[i]]$Treatment, 
           levels = c("No Additional Vignette", "Additional Vignette"))
}

## Visualize the results for China
ggplot(data = df.pid[[1]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Republican", "Non-Republican")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.98,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_pid_China.pdf", width = 6, height = 6, dpi = 500)

## Visualize the results for Country X
ggplot(data = df.pid[[2]], aes(x = Subgroup, y = Approval, fill = Treatment)) +
  geom_bar(stat = "identity", position = position_dodge(), color = "black") +
  scale_x_discrete(breaks = c("Republican", "Non-Republican")) +
  scale_fill_manual(values = c("grey90", "grey50")) +
  geom_errorbar(width = .2, aes(ymin = Lower_bound, ymax = Upper_bound), 
                position = position_dodge(.9)) +
  xlab("") + ylab("Approval Rate") +
  theme_classic() +
  theme(text = element_text(family = "Times", size = 14)) +
  theme(axis.text = element_text(color = "black", size = 14),
        legend.justification = c(1,1), legend.position = c(0.98,0.99),
        legend.box.background = element_rect(color = "black"), 
        legend.key.size = unit(1.5, "line")) +
  coord_cartesian(ylim = c(0,6.2))
ggsave("Figure_pid_CntryX.pdf", width = 6, height = 6, dpi = 500)
